# -*- coding:utf-8 -*-
#2022/3/1 8:31
# author:xwl

from fastapi import APIRouter, Depends

from backend.app.app.api.api_Xiong.crud.pri_crud import save_data_unit_caldata, save_data_unit_data, read_unit_input, \
    read_unit_output, read_data_unit_data
from backend.app.app.api.api_Xiong.models.x_model import input_data_recovery_save
from backend.app.app.api.api_v1.user import verify_token_user

dvp_proj_eco_evaluate = APIRouter(prefix="/dvp_proj_eco_evaluate", tags=["单元方案措施效果经济评价计算-数据恢复"])

#ver=Depends(verify_token_user)      'verify': ver
@dvp_proj_eco_evaluate.post("/save",name="存库")
def save(data:input_data_recovery_save,ver=Depends(verify_token_user)):
    well_caldata_result=save_data_unit_caldata(data.User_ID, data.Proj_ID,data.Data)
    save_input_success,save_output_success=save_data_unit_data(data.User_ID, data.Proj_ID,data.Inputdata, data.Outputdata)
    return {
        'caldata_result':well_caldata_result,
        'save_input_result':save_input_success,
        'save_output_result':save_output_success,
        'verify': ver
    }

@dvp_proj_eco_evaluate.post("/return_data",name="返回")
def return_data(User_ID,Proj_ID,ver=Depends(verify_token_user)):
    input_result=read_unit_input(User_ID,Proj_ID)
    output_result=read_unit_output(User_ID,Proj_ID)
    data=read_data_unit_data(User_ID,Proj_ID)
    return {
        'input_result':input_result,
        'output_result':output_result,
        'Data':data,
        'verify': ver
    }